#include "imagetool.h"

bool imageTool::loadImage(string filename, string basedir, ofImage* target, int type) 
{
	bool success;
	filename = basedir+"/"+filename;
	success = target->loadImage(filename);
	console::log("Load "+filename, success);
	if(success){
		if((type == OF_IMAGE_COLOR || type == OF_IMAGE_COLOR_ALPHA || type == OF_IMAGE_GRAYSCALE) && (type != target->type)){
			std::cout << "Converting image from " 
				<< imagetypeString(target->type) << " (" <<target->bpp << " bpp) to " << imagetypeString(type) << "." << endl;

			target->setImageType(type);
			cout << "New bitdepth is " << target->bpp << " bits per pixel." << endl;
		} 
		else{
			std::cout << "Image is " << imagetypeString(target->type) << "."
				<< " Bitdepth is " << target->bpp << " bpp." << endl;			
		}
	}
	return success;
}


string imageTool::imagetypeString(int type)
{
	switch(type){
	case OF_IMAGE_GRAYSCALE:
		{
			return "grayscale";
		}
	case OF_IMAGE_COLOR_ALPHA:
		{
			return "color+alpha";
		}
	case OF_IMAGE_COLOR:
		{
			return "color";
		}
	default:{
		return "unknown";
			}
	}
}